package filedemo2;

public class MainDemo4 {
    public static void main(String[] args) {
        System.out.println("遍历目录");
        java.io.File dir = new java.io.File("src"); //要遍历的目录
        visitAllDirsAndFiles(dir);
    }


    public static void visitAllDirsAndFiles(java.io.File dir) {
        System.out.println(dir);
        if (dir.isDirectory()) {
            String[] children = dir.list();
            for (int i = 0; i < children.length; i++) {
                visitAllDirsAndFiles(new java.io.File(dir, children[i]));
            }
        }
    }
}
